import { PureComponent } from 'react';
import {
	Row,
	Col,
	Form,
	Input,
	Select,
	Modal,
	TreeSelect,
	DatePicker
} from 'antd';
import SelectDeptTree from '@/components/SelectDeptTree';
import styles from './ProUserList.less';
const FormItem = Form.Item;
const { Option } = Select;


@Form.create()
class CreateForm extends PureComponent {
	
	constructor(props) {
	    super(props);
	    this.state = {
	    	getDeptTreeBySelectTree: "",
	    	confirmDirty: false,
	    }
	}
  
	selectedDeptTreeValue = (deptRecord) => {
		  this.setState({
  			getDeptTreeBySelectTree: deptRecord,
  		})
	}
	
	
	okHandle = () => {
		const { form,handleAdd } = this.props;
		const { getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if (err) return;
			form.resetFields();
			if(getDeptTreeBySelectTree) {
				fieldsValue.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				fieldsValue.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}
			
			if(fieldsValue.post) {
				fieldsValue.post_id = fieldsValue.post.key;
				fieldsValue.post_name = fieldsValue.post.label;
			}

			handleAdd(fieldsValue);
		});
	};
	
	coursePptChange = (e) => {
		
	}

  render() {
  		const {
				modalVisible,
				form,
				handleModalVisible,
				selectDeptTree,
				requestModelName,
				authForUser,
				postForUser,
				dispatch
			} = this.props;
	
	const changeTypeTree = [
	  {
	    title: '首授',
	    value: '0-1',
	    key: '0-1',
		isLeaf: true,
	  },
	  {
	    title: '按期晋升',
	    value: '0-2',
	    key: '0-2',
		isLeaf: true,
	  },
	  {
	    title: '晋职晋升',
	    value: '0-3',
	    key: '0-3',
		isLeaf: true,
	  },
	  {
	    title: '延期晋升',
	    value: '0-4',
	    key: '0-4',
		isLeaf: true,
	  },
	  {
	    title: '提前晋升',
	    value: '0-5',
	    key: '0-5',
		isLeaf: true,
	  },
	  {
	    title: '取消警衔',
	    value: '0-6',
	    key: '0-6',
		isLeaf: true,
	  },
	  {
	    title: '技术转行政',
	    value: '0-7',
	    key: '0-7',
		isLeaf: true,
	  },
	  {
	    title: '其它授衔部门转入',
	    value: '0-8',
	    key: '0-8',
		isLeaf: true,
	  },
	  {
	    title: '微调晋升',
	    value: '0-9',
	    key: '0-9',
		isLeaf: true,
	  },
	  {
	    title: '警衔降级',
	    value: '0-10',
	    key: '0-10',
		isLeaf: true,
	  },
	  {
	    title: '选升',
	    value: '0-11',
	    key: '0-11',
		isLeaf: true,
	  },
	  {
	    title: '不保留警衔',
	    value: '0-12',
	    key: '0-12',
		isLeaf: true,
	  },
	  {
	    title: '警衔变更',
	    value: '0-13',
	    key: '0-13',
		isLeaf: true,
	  },
	  {
	    title: '警衔保留',
	    value: '0-14',
	    key: '0-14',
		isLeaf: true,
	  },
	  
	];
return (
    <Modal
width={800}
destroyOnClose
title="新增"
visible={modalVisible}
onOk={this.okHandle}
onCancel={() => handleModalVisible()}
>
<Form  layout="vertical">
	
    
    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

        <Col  md={12} sm={24}>
	        <FormItem  label="政策条款名称">
	            {form.getFieldDecorator('lawpolicy', {
	            rules: [{ required: true, message: '请输入政策条款名称！',}],
	            })(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>


        <Col  md={12} sm={24}>
	        <FormItem  label="类型">
	            {form.getFieldDecorator('type', {
	            rules: [{ required: true, message: '请选择类型！'}],
	            })(
					<TreeSelect
				      	showSearch
				        style={{ width: '100%' }}
				        dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
				        treeData={changeTypeTree}
				        placeholder="请选择"
				        filterTreeNode={(input, treeNode) => 
				        	treeNode.props.title.toLowerCase().indexOf(input.toLowerCase()) >= 0
				        }
				    />
	            )}
	        </FormItem>
        </Col>

    </Row>
    
    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

        <Col  md={12} sm={24}>
	        <FormItem  label="实施时间">
	            {form.getFieldDecorator('starttime', {
	            rules: [{ required: true, message: '请选择实施时间！'}],
	            })(<DatePicker format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
	        </FormItem>
        </Col>


        <Col  md={12} sm={24}>
	        <FormItem  label="相关附件">
	            {form.getFieldDecorator('file', {
	            rules: [{ required: true, message: '请选择相关附件！'}],
	            })(
	            	<Input type="file" placeholder="请选择" οnChange={this.coursePptChange()}/>
	            )}
	        </FormItem>
        </Col>

    </Row>


</Form>
</Modal>
);
  }

}

export default CreateForm;